//
//  WKLoginView.m
//  WKMaybell
//
//  Created by 何文虎 on 2019/1/15.
//  Copyright © 2019 何文虎. All rights reserved.
//

#import "WKLoginView.h"

@interface WKLoginView ()<UITextFieldDelegate>
@property(nonatomic,strong)UITextField *mobileTx;
@property(nonatomic,strong)UITextField *passwordTx;
@property(nonatomic,strong)UIButton *loginBtn;
@property(nonatomic,strong)UIButton *forgetBtn;
@property(nonatomic,strong)UIButton *registerBtn;
@property(nonatomic,strong)UILabel *otherTitleLb;
@property(nonatomic,strong)UIButton *wechatBtn;
@property(nonatomic,strong)UIButton *qqBtn;
@property(nonatomic,strong)UIButton *weiboBtn;
@end

@implementation WKLoginView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self == [super initWithFrame:frame]) {
        [self setup];
    }
    return self;
}

- (void)setup{
    self.backgroundColor = [UIColor greenColor];
    [self addSubview:self.mobileTx];
    [self.mobileTx mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(10);
        make.left.mas_offset(30);
        make.right.mas_offset(-30);
        make.height.mas_offset(50);
    }];
    
    _mobileTx.keyboardType = UIKeyboardTypePhonePad;
    _mobileTx.returnKeyType = UIReturnKeyDone;
    _mobileTx.delegate = self;
    
    [self addSubview:self.passwordTx];
    [self.passwordTx mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.mobileTx.mas_bottom);
        make.left.mas_offset(30);
        make.right.mas_offset(-30);
        make.height.mas_offset(50);
    }];
    
    _passwordTx.keyboardType = UIKeyboardTypeASCIICapable;
    _passwordTx.returnKeyType = UIReturnKeyDone;
    _passwordTx.delegate = self;
    
    [self addSubview:self.loginBtn];
    [self.loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.passwordTx.mas_bottom).offset(40);
        make.left.mas_offset(30);
        make.right.mas_offset(-30);
        make.height.mas_offset(44);
    }];
    
    [self addSubview:self.forgetBtn];
    [self.forgetBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.loginBtn.mas_bottom).offset(15);
        make.right.mas_equalTo(-(ScreenWidth/2-8));
        make.width.mas_offset(100);
        make.height.mas_offset(20);
    }];
    
    [self addSubview:self.registerBtn];
    [self.registerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.forgetBtn.mas_top);
        make.left.mas_equalTo(ScreenWidth/2+8);
        make.width.mas_offset(100);
        make.height.mas_offset(20);
    }];
    
    [self addSubview:self.registerBtn];
    [self.registerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.forgetBtn.mas_top);
        make.left.mas_equalTo(ScreenWidth/2+8);
        make.width.mas_offset(100);
        make.height.mas_offset(20);
    }];
    
    [self addSubview:self.otherTitleLb];
    [self.otherTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.forgetBtn.mas_bottom).offset(45);
        make.width.mas_equalTo(ScreenWidth/2);
        make.centerX.mas_equalTo(self.mas_centerX);
        make.height.mas_offset(20);
    }];

    
    //QQ
    [self addSubview:self.qqBtn];
    [self.qqBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.otherTitleLb.mas_bottom).offset(30);
        make.width.mas_offset(40);
        make.height.mas_offset(60);
        make.centerX.mas_equalTo(self.mas_centerX);
    }];
    
    //微信
    [self addSubview:self.wechatBtn];
    [self.wechatBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.qqBtn.mas_top);
        make.width.mas_offset(40);
        make.height.mas_offset(60);
        make.right.mas_equalTo(self.qqBtn.mas_left).offset(-50);
    }];
    
    //微博
    [self addSubview:self.weiboBtn];
    [self.weiboBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.qqBtn.mas_top);
        make.width.mas_offset(40);
        make.height.mas_offset(60);
        make.left.mas_equalTo(self.qqBtn.mas_right).offset(50);
    }];
    
    


    
}


#pragma mark - UITextFieldDelegate
- (void)HiddenKeyBar{
    [_mobileTx resignFirstResponder];
    [_passwordTx resignFirstResponder];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self HiddenKeyBar];
    return YES;
}


- (UITextField*)mobileTx{
    if (!_mobileTx) {
        _mobileTx = [[UITextField alloc]init];
        _mobileTx.placeholder = @"填写手机号";
    }
    return _mobileTx;
}

- (UITextField*)passwordTx{
    if (!_passwordTx) {
        _passwordTx = [[UITextField alloc]init];
        _passwordTx.placeholder = @"密码";
    }
    return _passwordTx;
}

- (UILabel *)otherTitleLb{
    if (!_otherTitleLb) {
        _otherTitleLb = [[UILabel alloc]init];
        _otherTitleLb.text = @"第三方登录";
        _otherTitleLb.textColor = UIColorFromHex(0x979797);
        _otherTitleLb.font = PFSC_MediumFont(12);
        _otherTitleLb.textAlignment = NSTextAlignmentCenter;
    }
    return _otherTitleLb;
}

- (UIButton*)loginBtn{
    if (!_loginBtn) {
        _loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_loginBtn setTitle:@"登录" forState:UIControlStateNormal];
        [_loginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_loginBtn setBackgroundColor:BACK_COLOR];
        _loginBtn.layer.masksToBounds = YES;
        _loginBtn.layer.cornerRadius = 22;
    }
    return _loginBtn;
}

- (UIButton*)forgetBtn{
    if (!_forgetBtn) {
        _forgetBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_forgetBtn setTitle:@"忘记密码" forState:UIControlStateNormal];
        [_forgetBtn setTitleColor:UIColorFromHex(0x979797) forState:UIControlStateNormal];
        
    }
    return _forgetBtn;
}

- (UIButton*)registerBtn{
    if (!_registerBtn) {
        _registerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_registerBtn setTitle:@"立即注册" forState:UIControlStateNormal];
        [_registerBtn setTitleColor:UIColorFromHex(0x979797) forState:UIControlStateNormal];
    }
    return _registerBtn;
}


- (UIButton*)wechatBtn{
    if (!_wechatBtn) {
        _wechatBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_wechatBtn setImage:ImageNamed(@"complaint.png") forState:UIControlStateNormal];
        [_wechatBtn setTitle:@"微信" forState:UIControlStateNormal];
        [_wechatBtn setTitleColor:UIColorFromHex(0x3C3C3C) forState:UIControlStateNormal];
        _wechatBtn.titleLabel.font = PFSC_MediumFont(15);
        [_wechatBtn layoutButtonWithEdgeInsetsStyle:WHButtonEdgeInsetsStyleTop imageTitleSpace:12];
    }
    return _wechatBtn;
}

- (UIButton*)qqBtn{
    if (!_qqBtn) {
        _qqBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_qqBtn setImage:ImageNamed(@"complaint.png") forState:UIControlStateNormal];
        [_qqBtn setTitle:@"QQ" forState:UIControlStateNormal];
        [_qqBtn setTitleColor:UIColorFromHex(0x3C3C3C) forState:UIControlStateNormal];
        _qqBtn.titleLabel.font = PFSC_MediumFont(15);
        [_qqBtn layoutButtonWithEdgeInsetsStyle:WHButtonEdgeInsetsStyleTop imageTitleSpace:12];
    }
    return _qqBtn;
}

- (UIButton*)weiboBtn{
    if (!_weiboBtn) {
        _weiboBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_weiboBtn setImage:ImageNamed(@"complaint.png") forState:UIControlStateNormal];
        [_weiboBtn setTitle:@"微信" forState:UIControlStateNormal];
        [_weiboBtn setTitleColor:UIColorFromHex(0x3C3C3C) forState:UIControlStateNormal];
        _weiboBtn.titleLabel.font = PFSC_MediumFont(15);
        [_weiboBtn layoutButtonWithEdgeInsetsStyle:WHButtonEdgeInsetsStyleTop imageTitleSpace:12];
    }
    return _weiboBtn;
}

@end
